package com.starsea.book.ui.newpage.pop

import android.content.Context
import android.text.TextUtils
import android.widget.LinearLayout
import android.widget.RatingBar
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils
import com.lxj.xpopup.core.BottomPopupView
import com.starsea.book.R
import com.starsea.book.ui.newpage.normalview.RadiusEditText
import com.starsea.book.ui.newpage.normalview.RadiusTextView
import com.starsea.book.utils.visible

/**
 * @author Lee
 * @createTime 2023-08-04 16 GMT+8
 * @desc :
 */
class CommentPop(
    var mContext: Context,
    var reply: String,
    var commentType: String,
    var onResult: ((value: String, score: Float) -> Unit)? = null
) :
    BottomPopupView(mContext) {

    override fun getImplLayoutId(): Int {
        return R.layout.layout_comment_pop
    }

    override fun onCreate() {
        super.onCreate()

        val etContent = findViewById<RadiusEditText>(R.id.et_content)
        val rtv_send = findViewById<RadiusTextView>(R.id.rtv_send)
        val rb_rating = findViewById<RatingBar>(R.id.rb_rating)
        val ll_rating = findViewById<LinearLayout>(R.id.ll_rating)

        if (!TextUtils.isEmpty(reply))
            etContent.hint = "回复：${reply}"

        LogUtils.e(">>>> ", "commentType = " + commentType)
        ll_rating.visible(commentType == "1")

        rtv_send
            .setOnClickListener {
                val content = etContent.text.toString()
                if (TextUtils.isEmpty(content)) {
                    ToastUtils.showShort("请输入评论内容")
                    return@setOnClickListener
                }
                onResult!!.invoke(content, rb_rating.rating * 2)
                dismiss()
            }

    }

}